package com.tianji.learning.contoller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionAdminPageQuery;
import com.tianji.learning.domain.vo.QuestionAdminVO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.InteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author : Cammy.Wu
 * Description : 
 */

@Api(tags = "提问问题接口")
@RestController
@RequestMapping("/question")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final InteractionQuestionService interactionQuestionService;

    /**
     * 新增提问
     * @param questionFormDTO
     */
    @PostMapping
    @ApiOperation("新增问题")
    public void saveQuestion(@Valid @RequestBody QuestionFormDTO questionFormDTO) {
        interactionQuestionService.saveQuestion(questionFormDTO);
    }

    /**
     * 修改问题
     * @param id
     */
    @PutMapping("/{id}")
    @ApiOperation("修改问题")
    public void updateQuestion(@ApiParam("要修改的问题的id") @PathVariable("id") Long id, @RequestBody QuestionFormDTO questionFormDTO) {
        interactionQuestionService.updateQuestion(id, questionFormDTO);
    }

    /**
     * 用户端分页查询问题
     * @param query
     * @return
     */
    @GetMapping("page")
    @ApiOperation("用户端分页查询问题")
    public PageDTO<QuestionVO> queryQuestionPage(QuestionPageQuery query) {
        return interactionQuestionService.queryQuestionPage(query);
    }

    /**
     * 根据id查询问题详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO queryQuestionById(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        return interactionQuestionService.queryQuestionById(id);
    }

    /**
     * 根据id删除当前用户问题
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除当前用户问题")
    public void removeQuestion(@ApiParam(value = "问题id", example = "1") @PathVariable("id") Long id) {
        interactionQuestionService.removeQuestionById(id);
    }
}
